package logic

import (
	"book_srv/booksrvclient"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookPushLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBookPushLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookPushLogic {
	return &BookPushLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BookPushLogic) BookPush(req *types.BookPushRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	book, err := l.svcCtx.BookSrv.PushBook(l.ctx, &booksrvclient.PushBookRequest{
		Title:    req.Title,
		Image:    req.Image,
		AuthorId: req.UserId,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "发布成功",
		Data:    book,
	}, nil
}
